from ..extensions import db
from datetime import datetime

class Event(db.Model):
    __tablename__ = 'events'
    
    id = db.Column(db.BigInteger().with_variant(db.Integer, "sqlite"), primary_key=True, autoincrement=True, comment='活动ID')
    name = db.Column(db.String(200), nullable=False, comment='活动名称')
    start_time = db.Column(db.DateTime, nullable=False, comment='活动开始时间')
    end_time = db.Column(db.DateTime, nullable=False, comment='活动结束时间')
    registration_start_time = db.Column(db.DateTime, nullable=False, comment='报名开始时间')
    registration_end_time = db.Column(db.DateTime, nullable=False, comment='报名截止时间')
    url = db.Column(db.String(255), comment='活动图片')
    address = db.Column(db.String(255), comment='活动地址')
    description = db.Column(db.Text, comment='活动描述')
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow, comment='创建时间')
    
    def to_dict(self):
        return {
            'id': self.id,
            'name': self.name,
            'start_time': str(self.start_time) if self.start_time else None,
            'end_time': str(self.end_time) if self.end_time else None,
            'registration_start_time': str(self.registration_start_time) if self.registration_start_time else None,
            'registration_end_time': str(self.registration_end_time) if self.registration_end_time else None,
            'address': self.address,
            'description': self.description,
            'url': self.url,
            'created_at': str(self.created_at)
        }